﻿using PureMVC.Interfaces;
using System;

namespace PureMVC.Patterns.Observer
{
    public class Notifier : INotifier
    {
        public void InitializeNotifier(string _key)
        {
            MultitonKey = _key;
        }

        public void SendNotification(string _notificationName, object _body = null, string _type = null)
        {
            Facade.SendNotification(_notificationName, _body, _type);
        }

        protected IFacade Facade
        {
            get
            {
                if (MultitonKey == null)
                {
                    throw new Exception(MULTITON_MSG);
                }
                return Patterns.Facade.Facade.GetInstance(MultitonKey,
                    () => new Facade.Facade(MultitonKey));
            }
        }

        public string MultitonKey { get; protected set; }
        protected string MULTITON_MSG = "multitonKey for this Notifier not yet initialized!";
    }
}